/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sqlserver;

import java.io.File;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author PHAMDANH
 */
public class MyExtensionFileFilter extends FileFilter{
    String description;
    String extensions[];

    public MyExtensionFileFilter(String description, String[] extensions) 
    {
        if (description == null) 
            this.description = extensions[0];        
        else 
            this.description = description;
        this.extensions = extensions;
        StringToLower(this.extensions);
    }
    private void StringToLower(String str[]) 
    {
        for (int i = 0, n = str.length; i < n; i++) 
        {
            str[i] = str[i].toLowerCase();
        }
    }

    @Override
    public String getDescription() 
    {
        return description;
    }

    @Override
    public boolean accept(File fileName) 
    {
        if (!fileName.isDirectory()) 
        {
            String path = fileName.getAbsolutePath().toLowerCase();
            for (int i = 0; i<extensions.length; i++) 
            {
                String extension = extensions[i];
                if ((path.endsWith(extension) && (path.charAt(path.length() - extension.length() - 1)) == '.')) 
                {
                    return true;
                }
            }
        } 
        else        
            return true;
        return false;   
    }
}
